  <template>
  <div class="bob">
    <div id="login-box">
      <h1>Enroll</h1>
      <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="手机号" prop="number">
          <el-input v-model.number="ruleForm.number"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="pass">
          <el-input
            type="password"
            v-model="ruleForm.pass"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="确认密码" prop="checkPass">
          <el-input
            type="password"
            v-model="ruleForm.checkPass"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model.number="ruleForm.age"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button :plain="true" @click="queren">确认加入Mustang</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    var number = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("手机号不能为空"));
      }
      setTimeout(() => {
        if (!Number.isInteger(value)) {
          callback(new Error("请输入数字值"));
        } else {
          callback();
        }
      }, 1000);
    };
    var checkAge = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("年龄不能为空"));
      }
      setTimeout(() => {
        if (!Number.isInteger(value)) {
          callback(new Error("请输入数字值"));
        } else {
          if (value < 18) {
            callback(new Error("必须年满18岁"));
          } else {
            callback();
          }
        }
      }, 1000);
    };
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        if (this.ruleForm.checkPass !== "") {
          this.$refs.ruleForm.validateField("checkPass");
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.ruleForm.pass) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      ruleForm: {
        pass: "",
        checkPass: "",
        age: "",
        number: "",
      },
      rules: {
        pass: [{ validator: validatePass, trigger: "blur" }],
        checkPass: [{ validator: validatePass2, trigger: "blur" }],
        age: [{ validator: checkAge, trigger: "blur" }],
        number: [{ validator: number, trigger: "blur" }],
      },
    };
  },
  methods: {
    queren() {
      this.$message({ message: "恭喜你注册成功", type: "success" }),
        this.$router.push({
          path: "denglu",
        });
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style land="less"  scoped>
.el-input__inner {
  color: #ffffff;
  width: 20rem;
  font-size: 18px;
  border-bottom: 2px solid #ffffff;
  padding: 0.5rem 1rem;
  margin-bottom: 1.5rem;
  background: transparent;
}
.el-form-item__error {
  color: #f56c6c;
  font-size: 12px;
  line-height: 1;
  padding-top: 4px;
  position: absolute;
  top: 65%;
  left: 150px;
}
input::-webkit-input-placeholder {
  /* placeholder颜色  */
  color: #ffffff;
  /* placeholder字体大小  */
  font-size: 14px;
}
#login-box {
  position: absolute;
  top: 30%;
  left: 30%;
  width: 45rem;
  height: auto;
  /* height: 30rem; */
  background-color: #00000060; /*颜色的后两位是透明度*/
  text-align: center;
  padding: 2rem 4rem;
  /* padding-bottom: 0; */
}
#login-box h1 {
  font-size: 3rem;
  margin: 1rem 0;
  color: #ffffff;
}
#login-box .form {
  padding: 1rem 0;
}
#login-box .form .item input {
  color: #ffffff;
  width: 20rem;
  font-size: 18px;
  border-bottom: 2px solid #ffffff;
  padding: 0.5rem 1rem;
  margin-bottom: 1.5rem;
  background: transparent;
  /* color: #ffffff; */
}
#login-box .form .item i {
  font-size: 1.8rem;
  color: #ffffff;
}
#login-box button {
  width: 18rem;
  height: 3rem;
  font-size: 2rem;
  font-weight: 700;
  color: #ffffff;
  border-radius: 1.5rem;
  background-image: linear-gradient(to right, #74ebd5 0%, #9face6 100%);
}
</style>